package com.redis.springtest.jedis_test;

import redis.clients.jedis.Jedis;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * Jedis实现主从复制
 *
 * @author lzy
 * @date 2020 -08-07 下午12:14
 */
public class Jedis_MasterSlaveTest {

    public static void main(String[] args) {
        //创建Jedis实例。连接Redis本地服务
        Jedis jedis_master = new Jedis("10.2.55.77", 6379);
        Jedis jedis_slave = new Jedis("127.0.0.1", 6379);

        //设置6379服务器为主节点，使得6380服务器成为从节点
        jedis_slave.slaveof("10.2.55.77", 6379);

        //主节点写数据
        jedis_master.set("userName1", "zhangsan");
        jedis_master.set("age1", "18");

        //从节点读数据
        String userName = jedis_slave.get("userName1");
        String age = jedis_slave.get("age1");

        System.out.println("userName:" + userName + ",age:" + age);
    }

}
